package com.imooc.reader.portal;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.imooc.reader.portal.utils.SmsUtils;
import com.imooc.reader.portal.utils.impl.SmsMockUtils;
import com.imooc.reader.portal.utils.impl.SmsUtilsImpl;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@MapperScan("com.imooc.reader.portal.mapper")
@EnableCaching
public class PortalApplication {

	@Bean
	@ConditionalOnProperty(name="sms.mock",havingValue = "true",matchIfMissing = true)
	public SmsUtils smsMockUtils(){
		return new SmsMockUtils();
	}

	@Bean
	@ConditionalOnProperty(name="sms.mock",havingValue = "false",matchIfMissing = false)
	@ConfigurationProperties(prefix = "sms")
	public SmsUtils smsUtils(){
		return new SmsUtilsImpl();
	}

	@Bean
	public MybatisPlusInterceptor mybatisPlusInterceptor() {
		MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
		interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
		return interceptor;
	}

	public static void main(String[] args) {
		SpringApplication.run(PortalApplication.class, args);
	}

}
